package com.hung.tripleregistry.controller;

import com.hung.tripleregistry.core.model.RpcRegistry;
import com.hung.tripleregistry.core.result.ReturnT;
import com.hung.tripleregistry.service.RpcRegistryService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author Hung
 * @date 2022/10/3 21:31
 */
@Controller
@RequestMapping("/registry")
public class RegistryController {

    @Resource
    private RpcRegistryService rpcRegistryService;


    @RequestMapping("")
    public String index(Model model) {
        return "registry/registry.index";
    }

    @RequestMapping("/pageList")
    @ResponseBody
    public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "0") int start,
                                        @RequestParam(required = false, defaultValue = "10") int length,
                                        String env,
                                        String key) {
        return rpcRegistryService.pageList(start, length, env, key);
    }

    @RequestMapping("/delete")
    @ResponseBody
    public ReturnT<String> delete(int id) {
        return rpcRegistryService.delete(id);
    }

    @RequestMapping("/update")
    @ResponseBody
    public ReturnT<String> update(RpcRegistry rpcRegistry) {
        return rpcRegistryService.update(rpcRegistry);
    }

    @RequestMapping("/add")
    @ResponseBody
    public ReturnT<String> add(RpcRegistry rpcRegistry) {
        return rpcRegistryService.add(rpcRegistry);
    }


}

